define(['app','echarts','echartsGL'],function(app,echarts){return {module: function($scope, $http, eventBusService, httpService, params, configService) {
	if(params.back == undefined){
		$scope.back = true ;
	}
	
	//返回
	$scope.goback = function(){
		window.history.back();
	}
	
	//获取教师学校总数
	$scope.all = function(fk_dictionary_school_type,fk_unit) {
		httpService.post(app.urls.unit_selectCountAtCenter,{"fk_dictionary_school_type":fk_dictionary_school_type,"fk_unit":fk_unit}, function (data) {
	        if ("0000" === data.code) {
	            $scope.form.student = data.data.xs;
	        } else {
	            alert(data.msg);
	        }
	    });
	}
	//条件筛选-学段
	httpService.post(app.urls.dictionary_selectByRule,{fk_rule:"182c0cbc8924435ab6773779d9f2f48f"},function(data){
		if("0000" === data.code){
			 $scope.stageList = data.data;
		}else{
			alert(data.msg);
		}
	});
    httpService.post(app.urls.schoolanalysis_selectStageConditon, {}, function (data) {
        if ("0000" === data.code) {
           
        } else {
            alert(data.msg);
        }
    });
    //条件筛选-学校
    $scope.findUnit = function(fk_dictionary_school_type){
        httpService.post(app.urls.schoolanalysis_selectUnitConditon, {"fk_dictionary_school_type":fk_dictionary_school_type}, function (data) {
            if ("0000" === data.code) {
                $scope.schoolList = data.data;
            } else {
                alert(data.msg);
            }
        });
    }
    $scope.findUnit();
    $scope.findStage = function(fk_dictionary_school_type) {
    	$scope.findUnit(fk_dictionary_school_type);
    	$scope.find(fk_dictionary_school_type);
    }
	$scope.find = function(fk_dictionary_school_type,fk_unit) {
		$scope.all(fk_dictionary_school_type,fk_unit);
		//学生-年级
        httpService.post(app.urls.studentanalysis_selectGrade, {"fk_dictionary_school_type":fk_dictionary_school_type,"fk_unit":fk_unit}, function (data) {
            if ("0000" === data.code) {
                $scope.grade = data.data;
                $scope.grade.name = [];
                $scope.grade.value = [];
                for (var i = 0; i < $scope.grade.length; i++) {
                    $scope.grade.name.push($scope.grade[i].name);
                    $scope.grade.value.push($scope.grade[i].value);
                }
                $scope.echartsInitGrade();
            } else {
                alert(data.msg);
            }
        });
        $scope.echartsInitGrade = function () {
            // 基于准备好的dom，初始化echarts图表
            var myChart = echarts.init(document.getElementById("mobile_analysis_student_fk_grade"));
            var chartName = $scope.grade.name;
            var chartData = $scope.grade.value;
            var myColor = ['#25C68A', '#6E5EFF', '#FF865D', '#52C41A', '#3396FF', '#A96CFF', '#13C2C2', '#ff8700', '#1313ff', '#b7b86f'];
            option = {
                backgroundColor: '#fff',
                grid: {
                    left: '2%',
                    right: '10%',
                    top:'0%',
                    bottom:'0%',
                    containLabel: true
                },
                xAxis: [{
                    show: false,
                },
                    {
                        show: false,
                    }
                ],
                yAxis: {
                    type: 'category',
                    inverse: true,
                    show: false
                },
                series: [
                    //亮色条 百分比
                    {
                        show: true,
                        type: 'bar',
                        barGap: '-100%',
                        barWidth: '20%',
                        z: 2,
                        itemStyle: {
                            normal: {
                                color: function(params) {
                                    var num = myColor.length;
                                    return myColor[params.dataIndex % num]
                                }
                            }
                        },
                        label: {
                            normal: {
                                show: true,
                                textStyle: {
                                    color: '#999',
                                    fontSize: 8,
                                },
                                position: 'right',
                                formatter: function(data) {
                                    return (chartData[data.dataIndex])+'人';
                                }
                            }
                        },
                        data: chartData,
                    },
                    //年份
                    {
                        show: true,
                        type: 'bar',
                        xAxisIndex: 1, //代表使用第二个X轴刻度
                        barGap: '-100%',
                        barWidth: '10%',
                        itemStyle: {
                            normal: {
                                barBorderRadius: 200,
                                color: 'transparent'
                            }
                        },
                        label: {
                            normal: {
                                show: true,
                                position: [0, '-10'],
                                textStyle: {
                                    fontSize:10,
                                    color: '#666',
                                },
                                formatter: function(data) {
                                    return chartName[data.dataIndex];
                                }
                            }
                        },
                        data: chartData
                    }
                ]
            };
            myChart.setOption(option);
        }
		 //学生-性别
	    httpService.post(app.urls.studentanalysis_selectSex, {"fk_dictionary_school_type":fk_dictionary_school_type,"fk_unit":fk_unit}, function (data) {
	        if ("0000" === data.code) {
	            $scope.stusex = data.data;
	            $scope.echartsInitStuSex();
	        } else {
	            alert(data.msg);
	        }
	    });
	    $scope.echartsInitStuSex = function () {
	        // 基于准备好的dom，初始化echarts图表
	        var myChart = echarts.init(document.getElementById("mobile_analysis_student_sex"));
	        var colorList = ['#cf9ef1', '#9b8bff'];
	        var data = $scope.stusex;
	        var xdata = [];
	        var ydata = [];
	        var sundata = '';
	        for (var i = 0; i < data.length; i++) {
	            xdata.push(data[i].name);
	            ydata.push(data[i].value);
	        }
	
	        function sum(arr) {
	            return eval(arr.join("+"));
	        };
	        sundata = sum(ydata);
	        option = {
	            backgroundColor: "#fff",
	            title: {
	                text: sundata + "人",
	                //subtext:'总平均值(分)',
	                x: 'center',
	                y: 'center',
	                textStyle: {
	                    fontSize: 14,
	                    fontWeight: 'normal',
	                    color: ['#666']
	                },
	                subtextStyle: {
	                    color: '#999',
	                    fontSize: 12
	                },
	            },
	            grid: {
	                bottom: 0,
	                left: 0,
	                right: '10%'
	            },
	            legend: {
	                show: true,
	                orient: 'horizontal',
	                bottom: "bottom",
	                textStyle: {
	                    color: '#999',
	                    fontSize: 12,
	                },
	                data: xdata,
	                icon: 'roundRect'
	            },
	            series: [
	                // 主要展示层的
	                {
	                    radius: ['25%', '51%'],
	                    center: ['50%', '50%'],
	                    type: 'pie',
	                    itemStyle: {
	                        normal: {
	                            color: function (params) {
	                                return colorList[params.dataIndex]
	                            }
	                        }
	                    },
	                    labelLine: {
	                        normal: {
	                            show: true,
	                            length: 15,
	                            length2: 60,
	                            lineStyle: {
	                                color: '#d3d3d3'
	                            },
	                            align: 'right'
	                        },
	                        color: "#000",
	                        emphasis: {
	                            show: true
	                        }
	                    },
	                    label: {
	                        normal: {
	                            formatter: function (params) {
	                                var str = '' + '{rate|' + params.value + '}';
	                                return str
	                            },
	                            padding: [0, -50],
	                            height: 40,
	                            rich: {
	                                nameStyle: {
	                                    fontSize: 12,
	                                    color: "#555",
	                                    align: 'left'
	                                },
	                                rate: {
	                                    fontSize: 12,
	                                    color: "#1ab4b8",
	                                    align: 'left'
	                                }
	                            }
	                        }
	                    },
	                    data: $scope.stusex,
	                },
	                // 边框的设置
	                {
	                    radius: ['47%', '51%'],
	                    center: ['50%', '50%'],
	                    type: 'pie',
	                    label: {
	                        normal: {
	                            show: false
	                        },
	                        emphasis: {
	                            show: false
	                        }
	                    },
	                    labelLine: {
	                        normal: {
	                            show: false
	                        },
	                        emphasis: {
	                            show: false
	                        }
	                    },
	                    animation: false,
	                    tooltip: {
	                        show: false
	                    },
	                    itemStyle: {
	                        normal: {
	                            color: 'rgba(250,250,250,0.5)'
	                        }
	                    },
	                    data: [{
	                        value: 1,
	                    }],
	                }
	            ]
	        };
	        myChart.setOption(option);
	    }
	}
	$scope.find();
}}});